
/**
 * jqGrid 商品数据列表加载方法
 */
var prodInfo = function(contextPath ,grid_prod_selector, pager_prod_selector,unit) {
    if(unit == '包'){
        unit = '条'
    } else if(unit == '条'){
        unit = '包'
    } else {
        unit = '';
    }

    var filters = {
        "rules": [
            // {"field": "typeId", "data": '05'},
            {"field": "remark", "data": '科泰'},
            {"field": "unit", "data": unit},
        ]
    };
    console.log(filters)
    jQuery(grid_prod_selector).jqGrid({
        subGrid: false,
        url : contextPath+'/ktProd/getProdInfo',
        datatype: "json",
        mtype: 'POST',
        postData: {"filters": JSON.stringify(filters)},
        height: 300,
        colNames: ['ID', '商品名称', 'supplierId', '供应名称', '类型', '条码','单价','状态','单位','规格', '操作时间'],
        colModel: [
            {name: 'id', index: 'id', editable: true, hidden: true,},
            {
                name: 'productName',
                index: 'productName',
//                    width: 90,
                editable: true,
                sortable: false,
                editrules: {required: true}
            },
            {name: 'supplierId', index: 'productId', editable: true, hidden: true,},
            {
                name: 'supplierName', index: 'productId',
//                    width: 78,
                editable: true,
                hidden: true,
            },
            {
                name: 'prodTypeName',
                index: 'prodTypeName',
//                    width: 60,
                editable: true,
                sortable: false,
                editrules: {required: true}
            },
            {
                name: 'productCode',
                index: 'productCode',
//                    width: 60,
                editable: true,
                sortable: false,
                dataType: 'int', sortable: true,
                editrules: {required: true}
            },
            {
                name: 'cstPrice',
                index: 'cstPrice',
//                    width: 60,
                editable: true,
                sortable: false,
                hidden: true,
                editrules: {required: true}
            },
            {
                name: 'state',
                index: 'state',
//                    width: 40,
                editable: true,
                hidden: true,
                sortable: false,
                edittype: 'select',
                formatter: function (v, x, r) {
                    return r['state'] == "1" ? "有效" : "无效";
                },
                editoptions: {value: "0:有效;1:无效"}

            },
            {
                name: 'unit',
                index: 'unit',
//                    width: 30,
                editable: true,
                sortable: false
            },{
                name: 'spec',
                index: 'spec',
//                    width: 60,
                editable: true,
                sortable: false
            },
            {
                name: 'stateDate', index: 'stateDate',
//                    width: 60,
                editable: false, hidden: true,
            }

        ],
//                rownumbers: true, //自动行数
        height:"100%",   //高度自适应
//			width: "100%",
        autowidth: true,  //宽度自适应
        viewrecords: true,
        rowNum: 10,
        rowList: [10, 20, 30],
        pager: pager_prod_selector,
        altRows: true,
        //toppager: true,

        multiselect: true,
        //multikey: "ctrlKey",
        multiboxonly: false,


        loadComplete: function () {
            var table = this;
            setTimeout(function () {
                styleCheckbox(table);
                updateActionIcons(table);
                updatePagerIcons(table);
                enableTooltips(table);
            }, 0);
        },

        editurl: "${contextPath}/ktProd/getProdInfo",//nothing is saved
//            caption: "商品列表",
        jsonReader: {
            root: "recordList",
            page: "currentPage",
            total: "pageCount",
            records: "recordCount"
        }
    });
    $(".ui-jqgrid-bdiv").css("height", "351px");
    $("#grid-prod-pager_center").css("width","350px");
}


/**
 * jqGrid 烟品数据列表加载方法
 */
var sellProdInfo = function(contextPath ,grid_prod_selector, pager_prod_selector,unit) {
    if(unit == '包'){
        unit = '条'
    } else if(unit == '条'){
        unit = '包'
    } else {
        unit = '';
    }
    var filters = {
        "rules": [
            {"field": "remark", "data": '科泰'},
            {"field": "typeId", "data": '05'},
            {"field": "unit", "data": unit},
        ]
    };
    console.log(filters)
    jQuery(grid_prod_selector).jqGrid({
        subGrid: false,
        url : contextPath+'/ktProd/getProdInfo',
        postData: {"filters": JSON.stringify(filters)},
        datatype: "json",
        mtype: 'POST',
        height: 300,
        colNames: ['ID', '商品名称', 'supplierId', '供应名称', '类型', '条码','单价','状态','单位','规格', '操作时间'],
        colModel: [
            {name: 'id', index: 'id', editable: true, hidden: true,},
            {
                name: 'productName',
                index: 'productName',
//                    width: 90,
                editable: true,
                sortable: false,
                editrules: {required: true}
            },
            {name: 'supplierId', index: 'productId', editable: true, hidden: true,},
            {
                name: 'supplierName', index: 'productId',
//                    width: 78,
                editable: true,
                hidden: true,
            },
            {
                name: 'prodTypeName',
                index: 'prodTypeName',
//                    width: 60,
                editable: true,
                sortable: false,
                editrules: {required: true}
            },
            {
                name: 'productCode',
                index: 'productCode',
//                    width: 60,
                editable: true,
                sortable: false,
                dataType: 'int', sortable: true,
                editrules: {required: true}
            },
            {
                name: 'cstPrice',
                index: 'cstPrice',
//                    width: 60,
                editable: true,
                sortable: false,
                hidden: true,
                editrules: {required: true}
            },
            {
                name: 'state',
                index: 'state',
//                    width: 40,
                editable: true,
                hidden: true,
                sortable: false,
                edittype: 'select',
                formatter: function (v, x, r) {
                    return r['state'] == "1" ? "有效" : "无效";
                },
                editoptions: {value: "0:有效;1:无效"}

            },
            {
                name: 'unit',
                index: 'unit',
//                    width: 30,
                editable: true,
                sortable: false
            },{
                name: 'spec',
                index: 'spec',
//                    width: 60,
                editable: true,
                sortable: false
            },
            {
                name: 'stateDate', index: 'stateDate',
//                    width: 60,
                editable: false, hidden: true,
            }

        ],
//                rownumbers: true, //自动行数
        height:"100%",   //高度自适应
//			width: "100%",
        autowidth: true,  //宽度自适应
        viewrecords: true,
        rowNum: 10,
        rowList: [10, 20, 30],
        pager: pager_prod_selector,
        altRows: true,
        //toppager: true,

        multiselect: true,
        //multikey: "ctrlKey",
        multiboxonly: false,


        loadComplete: function () {
            var table = this;
            setTimeout(function () {
                styleCheckbox(table);
                updateActionIcons(table);
                updatePagerIcons(table);
                enableTooltips(table);
            }, 0);
        },

        editurl: "${contextPath}/ktProd/getProdInfo",//nothing is saved
//            caption: "商品列表",
        jsonReader: {
            root: "recordList",
            page: "currentPage",
            total: "pageCount",
            records: "recordCount"
        }
    });
    $("#grid-prod-pager_center").css("width","350px");
}

/**
 * 搜索商品
 */
var searchShopProduct = function(grid_prod_selector,unit) {
    if(unit == '包'){
        unit = '条'
    } else if(unit == '条'){
        unit = '包'
    } else {
        unit = "";
    }
    var supplierName = $("#supplierName").val();
    var productCode = $("#productCode").val();
    var state = $("#state1").val();
    var productName = $("#productName").val();
    var typeId = queryModel.parentId == null ? "" : queryModel.parentId;

    var filters = {
        "rules": [
            {"field": "productCode", "data": productCode},
            {"field": "productName", "data": productName},
//                {"field": "supplierName", "data": supplierName},
            {"field": "typeId", "data": typeId},
            {"field": "unit", "data": unit},
            {"field": "remark", "data": '科泰'},
        ]
    };
    console.log(JSON.stringify(filters))
    jQuery(grid_prod_selector).jqGrid('setGridParam', {
        postData: {
            "filters": JSON.stringify(filters) //"{'rules' : [{'field' : 'shopName','data' : "+shopName+"},{'field' : 'state','data' : "+state+"}]}"
        }
    }).trigger("reloadGrid");
}
